/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.bean.UserBean;
import com.minierp.dao.SystemLogDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import com.minierp.helper.EncCommonHelper;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

public class SystemLogDaoImpl extends BaseDaoImpl implements SystemLogDao {
	public List<?> getAppCancList(Date startDate, Date endDate, String bt,
			String code, String creaName, long tsId, UserBean ub,
			int startIndex, int num) throws Exception {
		String str = "";
		if (startDate != null) {
			str = str + " and b.createTime>=:startDate";
		}

		if (endDate != null) {
			str = str + " and b.createTime<:endDate";
		}

		if (bt != null && !bt.equals("")) {
			str = str + " and b.actionCode=:bt";
		}

		if (code != null && !code.equals("")) {
			str = str + " and (b.ip like :code)";
		}

		if (creaName != null && !creaName.equals("")) {
			str = str + " and (b.createrName like :creaName)";
		}

		if (tsId != 0L) {
			str = str + " and b.tallySetId=" + tsId;
		} else {
			str = str
					+ EncCommonHelper.createTallySetSQLStr("b.tallySetId", ub,
							true);
		}

		String sql = "select b from com.minierp.model.SystemLog b where b.logType=\'CANCEL_LOG\'"
				+ str + " order by b.id desc";
		Session sess = null;

		List arg15;
		try {
			sess = this.getSession();
			Query q = sess.createQuery(sql);
			if (startDate != null) {
				q.setDate("startDate", startDate);
			}

			if (endDate != null) {
				q.setDate("endDate", endDate);
			}

			if (bt != null && !bt.equals("")) {
				q.setString("bt", bt);
			}

			if (code != null && !code.equals("")) {
				q.setString("code", "%" + code + "%");
			}

			if (creaName != null && !creaName.equals("")) {
				q.setString("creaName", "%" + creaName + "%");
			}

			q.setFirstResult(startIndex);
			q.setMaxResults(num);
			arg15 = q.list();
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg15;
	}

	public int getAppCancListCount(Date startDate, Date endDate, String bt,
			String code, String creaName, long tsId, UserBean ub)
			throws Exception {
		String str = "";
		if (startDate != null) {
			str = str + " and b.createTime>=:startDate";
		}

		if (endDate != null) {
			str = str + " and b.createTime<:endDate";
		}

		if (bt != null && !bt.equals("")) {
			str = str + " and b.actionCode=:bt";
		}

		if (code != null && !code.equals("")) {
			str = str + " and (b.ip like :code)";
		}

		if (creaName != null && !creaName.equals("")) {
			str = str + " and (b.createrName like :creaName)";
		}

		if (tsId != 0L) {
			str = str + " and b.tallySetId=" + tsId;
		} else {
			str = str
					+ EncCommonHelper.createTallySetSQLStr("b.tallySetId", ub,
							true);
		}

		String sql = "select count(*) from com.minierp.model.SystemLog b where b.logType=\'CANCEL_LOG\'"
				+ str;
		Session sess = null;

		int arg14;
		try {
			sess = this.getSession();
			Query q = sess.createQuery(sql);
			if (startDate != null) {
				q.setDate("startDate", startDate);
			}

			if (endDate != null) {
				q.setDate("endDate", endDate);
			}

			if (bt != null && !bt.equals("")) {
				q.setString("bt", bt);
			}

			if (code != null && !code.equals("")) {
				q.setString("code", "%" + code + "%");
			}

			if (creaName != null && !creaName.equals("")) {
				q.setString("creaName", "%" + creaName + "%");
			}

			List list = q.list();
			if (list.isEmpty()) {
				return 0;
			}

			arg14 = Integer.parseInt(list.get(0).toString());
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg14;
	}
}